//
//  BaseViewController.m
//  ProjectA
//
//  Created by dllo on 16/1/24.
//  Copyright © 2016年 刘旺辉. All rights reserved.
//

#import "BaseViewController.h"


@interface BaseViewController ()
@end

@implementation BaseViewController

- (void)dealloc {
    
    [_barBackgroundView release];
    // 必须在dealloc方法中移除观察
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsCompact];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setLightDayModel) name:kLightDayModelNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setNightDayModel) name:kNightDayModelNotification object:nil];
    
    self.barBackgroundView = [[UIView alloc]init];
    self.barBackgroundView.frame = CGRectMake(0, -20, [UIScreen mainScreen].bounds.size.width, 64);
    [self.navigationController.navigationBar insertSubview:self.barBackgroundView atIndex:0];
    [_barBackgroundView release];
    self.barBackgroundView.userInteractionEnabled = NO;  // 关键之处
    
    [self getUserIfno];

}
- (void)getUserIfno {
    
    if (ISNIGHT) {
        [self setNightDayModel];
    } else {
        [self setLightDayModel];
    }
    
}
- (void)setLightDayModel {
    NSLog(@"-------设置白天模式");
    // 设置状态栏颜色
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    
    // 背景颜色
    self.view.backgroundColor = RGBA(255, 251, 222, 1);
    
    // 导航栏背景颜色
    self.barBackgroundView.backgroundColor = L_COLOR_CLEAR;
    
    // tabBar字的颜色
    [self.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:L_COLOR_BLACK} forState:UIControlStateNormal];
    
    // tabBar的背景颜色
    [self.tabBarController.tabBar setBarTintColor:RGBA(44, 211, 209, 1)];
    
    // 导航栏左侧item的颜色
    self.navigationItem.leftBarButtonItem.tintColor = L_COLOR_WHITE;

    // 导航栏字的颜色
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:L_COLOR_BLACK}];
    
    self.tabBarController.tabBar.tintColor = L_COLOR_WHITE;
    

    [UIViewForActivityIndicator shareActivityIndicatorViewWithFrame:self.view.frame].backgroundColor = RGBA(255, 251, 222, 1);
}

- (void)setNightDayModel {
    NSLog(@"-------设置夜晚模式");
    
    // 设置状态栏颜色
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
    // 背景颜色
    self.view.backgroundColor = RGBA(52, 52, 52, 1);
    
    // 导航栏背景颜色
    self.barBackgroundView.backgroundColor = L_COLOR_CLEAR;
    
    // tabBar字的颜色
    [self.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:L_COLOR_WHITE} forState:UIControlStateNormal];
    
    // tabBar的背景颜色
    [self.tabBarController.tabBar setBarTintColor:RGBA(52, 52, 52, 1)];
    
    // 导航栏左侧item的颜色
    self.navigationItem.leftBarButtonItem.tintColor = L_COLOR_WHITE;
    
    // 导航栏字的颜色
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:L_COLOR_WHITE}];
    
    self.tabBarController.tabBar.tintColor = L_COLOR_WHITE;
    
     [UIViewForActivityIndicator shareActivityIndicatorViewWithFrame:self.view.frame].backgroundColor = RGBA(52, 52, 52, 1);

}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
